home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Text / Single_Space_Buffer.bsh < prev   
Encoding:
Text File  |  2004-08-29  |  1.4 KB  |  60 lines

  1. /**
  2.  * Single_Space_Buffer.bsh - A Beanshell macro for jEdit that 
  3.  * converts a buffer from being double-spaced (where every second
  4.  * line is blank) to single-spaced, by removing each second line -
  5.  * but only if they're all blank.
  6.  *
  7.  * Copyright (C) 2004 Ollie Rutherfurd <oliver@rutherfurd.net>
  8.  *
  9.  * $Id: Single_Space_Buffer.bsh,v 1.1 2004/03/19 15:58:00 spestov Exp $
  10.  */
  11.  
  12. void singleSpaceBuffer(View view)
  13. {
  14.     Buffer buffer = view.getBuffer();
  15.     int line = 1;    // start on second line
  16.     Vector lines = new java.util.Stack();
  17.  
  18.     try
  19.     {
  20.         while(line < buffer.getLineCount())
  21.         {
  22.             if(buffer.getLineText(line).equals(""))
  23.                 lines.addElement(new Integer(line));
  24.             else
  25.             {
  26.                 StringBuffer msg = new StringBuffer();
  27.                 msg.append(buffer.getPath() + " doesn't appear to be double-spaced:\n");
  28.                 msg.append("Line " + (line + 1) + " isn't blank.");
  29.                 Macros.error(view, msg.toString());
  30.                 return;
  31.             }
  32.             line += 2;
  33.         }
  34.         while(!lines.empty())
  35.         {
  36.             Integer lineno = (Integer)lines.pop();
  37.             int offset = buffer.getLineStartOffset(lineno.intValue());
  38.             buffer.remove(offset-1,1);
  39.         }
  40.     }
  41.     finally
  42.     {
  43.         if(buffer.insideCompoundEdit())
  44.             buffer.endCompoundEdit();
  45.     }
  46. }
  47.  
  48. singleSpaceBuffer(view);
  49.  
  50. /*
  51.  
  52. <listitem>
  53.     <para><filename>Single_Space_Buffer.bsh</filename></para>
  54.     <abstract><para>
  55.         Removes every second line, if they are all blank.
  56.     </para></abstract>
  57. </listitem>
  58.  
  59. */
  60.